package com.pi.config;



import com.pi.common.CodesConstants;
import com.pi.pro.xcmg.am.common.XcmgAmConstants;
import com.pi.pro.xcmg.am.was.fac.calculator.SlocationPaSeqPutawayCalculator;
import com.pi.pro.xcmg.am.was.fac.calculator.WaveLotattrShipAllocator;
import com.pi.pro.xcmg.am.was.fac.handler.AsnCustomPredicate;
import com.pi.pro.xcmg.am.was.fac.handler.SoCustomPredicate;
import com.pi.wms.common.WmsConstants;
import com.pi.wms.entity.TwaDocAsnHeader;
import com.pi.wms.entity.TwaDocSoHeader;
import com.pi.wms.fac.CustomPredicateQuery;
import com.pi.wms.fac.PutawayCalculator;
import com.pi.wms.fac.ShipAllocator;
import com.pi.wms.fac.WaveSoAllocator;
import com.pi.wms.fac.impl.WaveSoSequenceAllocator;
import com.pi.wms.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;


/**
 *
 */
@Slf4j
@Configuration
public class XcmgAmWasStartupConfig {


    @Autowired
    private PutawayService putawayService;

    @Autowired
    private AsnService asnService;

    @Autowired
    private SoService soService;

    @Autowired
    private WaveService waveService;

    @Autowired
    private AllocationService allocationService;


/**********************************************/
//** FACTORY
/**********************************************/


    @Bean
    public PutawayCalculator slocPaSeqPutawayCalculator(){
        SlocationPaSeqPutawayCalculator calculator=new SlocationPaSeqPutawayCalculator();
        putawayService.rigister(calculator);
        return calculator;
    }

    @Bean
    @Order(801100010)
    public WaveSoAllocator waveSoSeqAllocator(){
        WaveSoAllocator allocator= new WaveSoSequenceAllocator(WmsConstants.PUTAWAY_RULE_MATERIAL_LOC_ASSOCIATE_CALCULATOR);
        String m = this.allocationService.rigister(allocator);
        log.debug("Configuration XcmgAmWasConfig create waveSoSequenceAllocator//{}",m);
        return allocator;
    }


    @Bean
    public ShipAllocator waveLotattrShipAllocator(){
        WaveLotattrShipAllocator allocator=new WaveLotattrShipAllocator(CodesConstants.COMMON_WILDCARD + "/"  + XcmgAmConstants.SHIP_RULE_WAVE_LOTATTR_ALLOCATOR);
        String m = allocationService.rigister(allocator);
        log.debug("Configuration WmsActServiceConfig create waveLotattrShipAllocator//{}",m);
        return allocator;
    }


    @Bean
    public CustomPredicateQuery soCustomPredicate(){
        CustomPredicateQuery<TwaDocSoHeader> ppredicate=new SoCustomPredicate();
        if (this.soService!=null){
            this.soService.customPredicate(ppredicate);
        }
        return ppredicate;
    }

    @Bean
    public CustomPredicateQuery asnCustomPredicate(){
        CustomPredicateQuery<TwaDocAsnHeader> apredicate=new AsnCustomPredicate();
        if (this.asnService!=null){
            this.asnService.customPredicate(apredicate);
        }
        return apredicate;
    }


    /**
    @Bean
    public CustomPredicateQuery waveCustomPredicate(){
        CustomPredicateQuery<TwaDocWaveHeader>  wavepredicate=new WaveCustomPredicate();
        if (this.waveService!=null){
            this.waveService.customPredicate(wavepredicate);
        }
        return wavepredicate;
    }
    **/
}
